/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package rg1oopdemo1;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Bob50
 */
public class CheckPhone {

    /**
     * 判断一个电话号码是否合法
     * @param phoneNumber 所判读的电话号码
     * @return 判断的结果
     */
    public static boolean isPhoneNumber(String phoneNumber) {
        String regex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$";
        if (phoneNumber.length() != 11) {
            return false;
        } else {
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(phoneNumber);
            boolean isMatch = m.matches();
            if (isMatch) {
                return true;
            } else {
                return false;
            }
        }
    }

}
